using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace ICP_MS.Plugin.Experiment;

public class FormWait : Form
{
	private BackgroundWorker worker = new BackgroundWorker();

	private IContainer components = null;

	private ProgressBar progressBar1;

	public event EventHandler<ExpDataArgs> Run = null;

	public event EventHandler Complete = null;

	public FormWait()
	{
		InitializeComponent();
	}

	private void FormWait_Load(object sender, EventArgs e)
	{
		worker.WorkerReportsProgress = true;
		worker.DoWork += worker_DoWork;
		worker.RunWorkerCompleted += worker_RunWorkerCompleted;
		worker.RunWorkerAsync();
		ApplyResources();
	}

	private void ApplyResources()
	{
		Text = Lang.Txt("FormWait.Title.Text");
	}

	private void worker_DoWork(object sender, DoWorkEventArgs e)
	{
		if (this.Run != null)
		{
			this.Run(progressBar1, null);
		}
	}

	private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
	{
		if (this.Complete != null)
		{
			this.Complete(this, null);
		}
		Close();
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.progressBar1 = new System.Windows.Forms.ProgressBar();
		base.SuspendLayout();
		this.progressBar1.Location = new System.Drawing.Point(24, 35);
		this.progressBar1.Name = "progressBar1";
		this.progressBar1.Size = new System.Drawing.Size(288, 23);
		this.progressBar1.TabIndex = 0;
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(334, 107);
		base.Controls.Add(this.progressBar1);
		base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
		base.MaximizeBox = false;
		base.MinimizeBox = false;
		base.Name = "FormWait";
		base.Opacity = 0.6;
		base.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
		this.Text = "等待..";
		base.Load += new System.EventHandler(FormWait_Load);
		base.ResumeLayout(false);
	}
}
